package com.free.mini.core.serve.utils;

import java.io.Serializable;

import org.springframework.http.HttpStatus;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

/**
 * @author dongsufeng
 * @version 4.0
 * @date 2023/7/31 12:01
 */
@Slf4j
@Data
public class R<T> implements Serializable {

    private Integer code;
    private String msg;
    private T data;

    public R(Integer code,String msg,T data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public R() {
        this.code = 0;
        this.msg = "success";
    }

    public static R error() {
        return error(HttpStatus.INTERNAL_SERVER_ERROR.value(), "未知异常，请联系管理员");
    }

    public static R error(String msg) {
        return error(HttpStatus.INTERNAL_SERVER_ERROR.value(), msg);
    }

    public static R error(int code, String msg) {
        R r = new R();
        r.code = code;
        r.msg = msg;
        return r;
    }

    public static R ok(String msg) {
        R r = new R();
        r.msg = msg;
        return r;
    }

    public static R success(Object data) {
        R r = new R();
        r.data = data;
        return r;
    }

    public static R success() {
        return new R();
    }

}
